package com.example.hp.yuejian5.activity;


import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hp.yuejian5.R;
import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.bean.UserBean;
import com.example.hp.yuejian5.model.User_DetailModel;
import com.squareup.picasso.Picasso;

import static com.example.hp.yuejian5.other.url.USERPICTURE;

/**
 * A simple {@link Fragment} subclass.
 */
public class My_DetailActivity extends AppCompatActivity {
    private String i_id, u_id;
    private Context context;
    private RetrofitListener<UserBean> listener;

    private ImageView user_detail_pic;
    private SharedPreferences sp;
    private TextView user_detail_name,user_detail_gender,user_detail_tel,user_detail_email;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_my_detail);
        Intent intent = getIntent();
        i_id = (String) intent.getStringExtra("m_id");
        sp = getSharedPreferences("user_id", Context.MODE_PRIVATE);
        u_id = sp.getString("userid", null);
        initView();

        listener = new RetrofitListener<UserBean>() {
            @Override
            public void onSuccess(UserBean userBean, int flag) {
                user_detail_name.setText(userBean.getUser_name());
                if(userBean.getUser_gender().equals("1"))
                {
                    user_detail_gender.setText("男");
                }
                else
                    user_detail_gender.setText("女");

                user_detail_tel.setText(userBean.getUser_tel());
                user_detail_email.setText(userBean.getUser_email());

                Picasso.with(context).load(USERPICTURE + userBean.getUser_pic()).into(user_detail_pic);
            }

            @Override
            public void onFail() {

            }
        };


        userDetail();

    }



    private void initView() {
        user_detail_pic= findViewById(R.id.user_detail_pic);
        user_detail_name= findViewById(R.id.user_detail_name);
        user_detail_gender =findViewById(R.id.user_detail_gender);
        user_detail_tel =findViewById(R.id.user_detail_tel);
        user_detail_email=findViewById(R.id.user_detail_email);

    }


    private void userDetail() {
        User_DetailModel user_detailModel = new User_DetailModel();
        user_detailModel.userDetail(u_id, listener);
    }


}
